<template>
	<view class="wrap">
		<baseForm :column.sync="column" @changeColumn="changeColumn" @submitFun="submitFun"></baseForm>
	</view>
</template>

<script>
	import baseForm from '@/wxcomponents/form/form.vue';
	import login from '@/libs/login.js';
	import {
		format,
		dectList
	} from '@/libs/common.js';
	import {
		mapGetters
	} from 'vuex';
	import userMixins from '@/libs/userMixins.js'
	import formMixins from '@/libs/formMixins.js'
	export default {
		mixins: [userMixins, formMixins],
		data() {
			let self = this;
			return {
				column: [{
						label: '会议名称', //输入框title
						name: 'meetingName', //传值类型
						type: 'normalInput', //输入框类型
						mode: 'date',
						disabled: false, //是否禁用
						required: true, //是否必须填写
						value: '' //输入框的值
					},
					{
						label: '会议日期',
						name: 'meetingDate',
						type: 'picker',
						mode: 'date',
						required: true,
						disabled: false,
						value: format('YY-mm-dd', new Date()),
						text: format('YY-mm-dd', new Date())
					},
					{
						label: '会议起始时间',
						name: 'meetingStart',
						type: 'picker',
						mode: 'time',
						required: true,
						disabled: false,
						value: '',
						text: '请选择'
					},
					{
						label: '会议结束时间',
						name: 'meetingEnd',
						type: 'picker',
						mode: 'time',
						required: true,
						disabled: false,
						value: '',
						text: '请选择'
					},
					{
						label: '会议室',
						name: 'roomId',
						type: 'picker',
						mode: 'selector',
						required: true,
						disabled: false,
						value: '',
						text: '请选择',
						range: []
					},
					{
						label: '会议级别',
						name: 'meetingLevel',
						type: 'picker',
						mode: 'selector',
						required: true,
						disabled: false,
						value: '',
						text: '请选择',
						range: []
					},
					{
						label: '校内参会人员',
						name: 'participantsInner',
						type: 'tips',
						required: true,
						disabled: false,
						value: '',
						text: '',
						url: '/modules/department/departmentMenu',
						originUrl: '/modules/meeting/meetingApply',
						chooseItems: []
					},
					{
						label: '校外参会人员',
						name: 'participantsOuter',
						type: 'normalInput',
						disabled: false,
						required: false,
						value: '',
						url: ''
					},
					{
						label: '会议内容',
						name: 'meetingDesc',
						type: 'normalInput',
						disabled: false,
						required: false,
						value: ''
					},
					{
						label: '备注',
						name: 'remark',
						type: 'normalInput',
						hidden: true,
						required: false,
						value: ''
					},
					{
						label: '附件',
						type: 'upload',
						url: '/stu/common/uploadFile',
						docFileId: '',
						docFileUrl: '',
						docFileName: '',
						attachmentVoListStr: '',
						limitSize: 9,
						disabled: false
					}
				]
			};
		},
		onShow() {
			this.updateParamsWithCash();
			this.getMeetingRoom();
			this.getMeetLevel();
			this.column[6].chooseItems = this.$store.state.idsObj;
			this.EventBus.on('pickerChange', obj => {
				if (this[obj.key + 'Change']) {
					this[obj.key + 'Change'](obj.value);
				}
			})
		},
		onHide() {
			this.changeColumn(this.column)
			this.savePageTempParams({
				name: 'mettingApply',
				formModel: this.formModel,
				syncColumn: this.syncColumn
			})
		},
		methods: {
			meetingLevelChange(value) {
				let item = this.column[5].range.find(item => { return item.name == '其他' });
				let col = this.column.find(col => { return col.name == 'remark' });
				col.hidden = item.id != value;
			},
			//会议室获取
			async getMeetingRoom() {
				let resp = await this.$http.post({
					url: '/oa/meetingRoom/list'
				});
				this.column[4].range = resp.result.map(item => {
					return {
						name: item.roomName,
						id: item.id
					};
				});
			},
			//会议级别
			async getMeetLevel() {
				let resp = await dectList('dict_meeting_rank');
				this.column[5].range = resp.map(item => {
					return {
						name: item.dictName,
						id: item.dictValue
					};
				});
			},
			async submitFun() {
				let participantsInner = this.$store.state.idsObj.map(item => {
					return item.jobNumber
				})
				let params = {
					...this.formModel,
					jobNumber: this.user.number,
					participantsInner: participantsInner, //校内参会人:教职工号拼接,英文逗号,分隔
					teacherName: this.user.name,
					attachmentVoListStr: this.column[10].attachmentVoListStr, //附件列表
					meetingDate: this.column[1].text
				};
				let rules = [
					{
						key: 'meetingName',
						checkFunc(value) {
							if (!value)	return false;
							return true;
						},
						errMsg: '请输入会议名称'
					},
					{
						key: 'meetingStart',
						checkFunc(value) {
							if (!value)	return false;
							return true;
						},
						errMsg: '请选择会议起始时间'
					},
					{
						key: 'meetingEnd',
						checkFunc(value) {
							if (!value)	return false;
							return true;
						},
						errMsg: '请选择会议结束时间'
					},
					{
						key: 'roomId',
						checkFunc(value) {
							if (!value)	return false;
							return true;
						},
						errMsg: '请选择会议室'
					},
					{
						key: 'meetingLevel',
						checkFunc(value) {
							if (!value)	return false;
							return true;
						},
						errMsg: '请选择会议级别'
					},
					{
						key: 'participantsInner',
						checkFunc(value) {
							if (value.length == 0)	return false;
							return true;
						},
						errMsg: '请选择校内参会人员'
					},
				]
				let checkRes = this.checkFormIsPassRules(params, rules);
				if (!checkRes.isPass) {
					this.showToast(checkRes.errMsg);
					return;
				}
				let resp = await this.$http.post({
					url: '/oa/meetingApply/save',
					data: params
				});
				this.showToast('提交成功',()=> {uni.navigateBack()});
			}
		},
		components: {
			baseForm
		},
		computed: {
			
		},
		watch:{
		'$store.state.idsObj':{
			handler(){
				this.column[6].chooseItems = this.$store.state.idsObj;
			}
		}
		}

	};
</script>

<style lang="scss" scoped>
	page {
		min-height: 100%;
	}

	.wrap {
		height: 100%;
	}
</style>
